
include config.mak

LIBMATVEC=-L. -lmatvec
INCLUDES=-I.
OBJECTS=vector.o matrix.o transform.o determinant.o adjoint.o \
	camera.o world.o render.o gaussian_elim.o

TEST_PROGS= matvec_test matrix_test cpu_time_test dot_test dot2_test \
	render_test rot_test data_test inv_test ang_test             \
	gram_shmidt_orth_test space_trans_test

SHELL=/bin/bash

all: matvec test-progs mtxvecutils $(LIBS)

install: install-matvec install-utils

install-matvec:
	cp libmatvec*.so.$(VERSION) /usr/local/lib
	ldconfig -n /usr/local/lib
	if [ ! -e /usr/local/include/matvec ]; then \
	    mkdir /usr/local/include/matvec ; \
	fi
	cp *.h /usr/local/include/matvec

install-utils:
	cd mtx_utils && make install
	cd vec_utils && make install

# Test Programs

test-progs: matvec $(TEST_PROGS)
	if [ ! -e ../bin ]; then \
	    mkdir ../bin; \
	fi
	cp *_test ../bin

# Library creation

matvec: $(OBJECTS) 
	ld $(LD_FLAGS) -o libmatvec.so.$(VERSION) \
                $(OBJECTS) -lc -lm
	ln -nfs libmatvec.so.$(VERSION) libmatvec.so
	if [ ! -e ../bin ]; then \
	    mkdir ../bin; \
	fi
	cp libmatvec.* ../bin

# Object compilations

libmatvec_asm.so:
	cd arch && make
	ldconfig -v -n .

.c: 
	$(CC) $(CPP_FLAGS) $(INCLUDES) $(C_TEST_FLAGS) $< $(LIBMATVEC) -o $@

.c.o:
	$(CC) $(CPP_FLAGS) $(INCLUDES) $(C_FLAGS) $<

.s.o:
	$(ASM) $(ASM_FLAGS) $<

# mtx/vec utilities creation

mtxvecutils:
	cd mtx_utils && make
	cd vec_utils && make

# clean up

vec-clean:
	cd vec_utils && make clean

mtx-clean:
	cd mtx_utils && make clean

clean: mtx-clean vec-clean
	rm -f *.o
	rm -f *~
	rm -f libmatvec*
	rm -f *_test
	rm -rf ../bin/*
	cd arch && make clean

dist-clean: clean mtx-clean vec-clean
	rm -f config.mak config.h arch.s
	rm -f /usr/local/lib/libmatvec*.so*
	rm -rf /usr/local/include/matvec
